package com.shbaiche.bifenba.adapter.data;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shbaiche.bifenba.R;
import com.shbaiche.bifenba.model.GankResults;
import com.shbaiche.bifenba.model.match.MatchesVo;
import com.shbaiche.bifenba.ui.match.MatchDetailActivity;
import com.shbaiche.bifenba.view.CircularImage;

import butterknife.BindView;
import cn.droidlover.xdroid.base.SimpleRecAdapter;
import cn.droidlover.xdroid.kit.KnifeKit;
import cn.droidlover.xdroidbase.imageloader.ILFactory;

/**
 * Created by wanglei on 2016/12/10.
 */

public class DataScheduleListAdapter extends SimpleRecAdapter<MatchesVo, DataScheduleListAdapter.ViewHolder> {


    public DataScheduleListAdapter(Context context) {
        super(context);
    }

    @Override
    public ViewHolder newViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.adapter_data_schedule_list;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        MatchesVo item = data.get(position);

        ILFactory.getLoader().loadNet(holder.ivLogoHome, item.getHomeLogo(), null);
        ILFactory.getLoader().loadNet(holder.ivLogoVisie, item.getVisitLogo(), null);

        if(!TextUtils.isEmpty(item.dateShow)){
            holder.tvTime.setText(item.dateShow);
            if (position == 0){
                holder.tvTime.setVisibility(View.VISIBLE);
            }else{
                if(item.dateShow.equals(data.get(position-1).dateShow)){
                    holder.tvTime.setVisibility(View.GONE);
                }else{
                    holder.tvTime.setVisibility(View.VISIBLE);
                }
            }
        }else{
            holder.tvTime.setVisibility(View.GONE);
        }

        holder.tvNameHome.setText(item.getHomeName());
        holder.tvNameVisie.setText(item.getVisitName());
        holder.tvDate.setText(item.getDate() );
        holder.tvScore.setText(item.getHomeScore()+":"+item.getVisitScore());



        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getRecItemClick() != null) {
                    Intent intent = new Intent(context,MatchDetailActivity.class);
                    intent.putExtra("data",data.get(position));
                    context.startActivity(intent);
                }
            }
        });
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_logo_home)
        CircularImage ivLogoHome;

        @BindView(R.id.iv_logo_visit)
        CircularImage ivLogoVisie;

        @BindView(R.id.tv_name_home)
        TextView tvNameHome;

        @BindView(R.id.tv_name_visit)
        TextView tvNameVisie;

        @BindView(R.id.tv_time)
        TextView tvTime;

        @BindView(R.id.tv_date)
        TextView tvDate;

        @BindView(R.id.tv_score)
        TextView tvScore;





        public ViewHolder(View itemView) {
            super(itemView);
            KnifeKit.bind(this, itemView);
        }
    }
}
